1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using System.Data.SqlClient;
10 using Excel = Microsoft.Office.Interop.Excel;
11 namespace WarehouseManagementSystem
12 {
13 public partial class frmSalesRecord1 : Form
14 {
15
16 DataTable dTable;
17 SqlConnection con = null;
18 SqlDataAdapter adp;
19 DataSet ds;
20 SqlCommand cmd = null;
21 DataTable dt= new DataTable();
22 SqlDataReader rdr;
23 ConnectionString cs = new ConnectionString();
24
25 public frmSalesRecord1()
26 {
27 InitializeComponent();
28 }
29
30 private void frmSalesRecord_Load(object sender, EventArgs e)
31 {
32 FillCombo();
33 }
34
35 private void Button3_Click(object sender, EventArgs e)
36 {
37 if (DataGridView1.DataSource == null)
38 {
39 MessageBox.Show("Sorry nothing to export into excel sheet..", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
40 return;
41 }
42 int rowsTotal = 0;
43 int colsTotal = 0;
44 int I = 0;
45 int j = 0;
46 int iC = 0;
47 System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
48 Excel.Application xlApp = new Excel.Application();
49
50 try
51 {
52 Excel.Workbook excelBook = xlApp.Workbooks.Add();
53 Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelBook.Worksheets[1];
54 xlApp.Visible = true;
55
56 rowsTotal = DataGridView1.RowCount;
57 colsTotal = DataGridView1.Columns.Count - 1;
58 var _with1 = excelWorksheet;
59 _with1.Cells.Select();
60 _with1.Cells.Delete();
61 for (iC = 0; iC <= colsTotal; iC++)
62 {
63 _with1.Cells[1, iC + 1].Value = DataGridView1.Columns[iC].HeaderText;
64 }
65 for (I = 0; I <= rowsTotal - 1; I++)
66 {
67 for (j = 0; j <= colsTotal; j++)
68 {
69 _with1.Cells[I + 2, j + 1].value = DataGridView1.Rows[I].Cells[j].Value;
70 }
71 }
72 _with1.Rows["1:1"].Font.FontStyle = "Bold";
73 _with1.Rows["1:1"].Font.Size = 12;
74
75 _with1.Cells.Columns.AutoFit();
76 _with1.Cells.Select();
77 _with1.Cells.EntireColumn.AutoFit();
78 _with1.Cells[1, 1].Select();
79 }
80 catch (Exception ex)
81 {
82 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
83 }
84 finally
85 {
86 //RELEASE ALLOACTED RESOURCES
87 System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
88 xlApp = null;
89 }
90 }
91
92 private void Button4_Click(object sender, EventArgs e)
93 {
94 if (DataGridView2.DataSource == null)
95 {
96 MessageBox.Show("Sorry nothing to export into excel sheet..", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
97 return;
98 }
99 int rowsTotal = 0;
100 int colsTotal = 0;
101 int I = 0;
102 int j = 0;
103 int iC = 0;
104 System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
105 Excel.Application xlApp = new Excel.Application();
106
107 try
108 {
109 Excel.Workbook excelBook = xlApp.Workbooks.Add();
110 Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelBook.Worksheets[1];
111 xlApp.Visible = true;
112
113 rowsTotal = DataGridView2.RowCount;
114 colsTotal = DataGridView2.Columns.Count - 1;
115 var _with1 = excelWorksheet;
116 _with1.Cells.Select();
117 _with1.Cells.Delete();
118 for (iC = 0; iC <= colsTotal; iC++)
119 {
120 _with1.Cells[1, iC + 1].Value = DataGridView2.Columns[iC].HeaderText;
121 }
122 for (I = 0; I <= rowsTotal - 1; I++)
123 {
124 for (j = 0; j <= colsTotal; j++)
125 {
126 _with1.Cells[I + 2, j + 1].value = DataGridView2.Rows[I].Cells[j].Value;
127 }
128 }
129 _with1.Rows["1:1"].Font.FontStyle = "Bold";
130 _with1.Rows["1:1"].Font.Size = 12;
131
132 _with1.Cells.Columns.AutoFit();
133 _with1.Cells.Select();
134 _with1.Cells.EntireColumn.AutoFit();
135 _with1.Cells[1, 1].Select();
136 }
137 catch (Exception ex)
138 {
139 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
140 }
141 finally
142 {
143 //RELEASE ALLOACTED RESOURCES
144 System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
145 xlApp = null;
146 }
147 }
148
149 private void Button7_Click(object sender, EventArgs e)
150 {
151 if (DataGridView3.DataSource == null)
152 {
153 MessageBox.Show("Sorry nothing to export into excel sheet..", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
154 return;
155 }
156 int rowsTotal = 0;
157 int colsTotal = 0;
158 int I = 0;
159 int j = 0;
160 int iC = 0;
161 System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
162 Excel.Application xlApp = new Excel.Application();
163
164 try
165 {
166 Excel.Workbook excelBook = xlApp.Workbooks.Add();
167 Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelBook.Worksheets[1];
168 xlApp.Visible = true;
169
170 rowsTotal = DataGridView3.RowCount;
171 colsTotal = DataGridView3.Columns.Count - 1;
172 var _with1 = excelWorksheet;
173 _with1.Cells.Select();
174 _with1.Cells.Delete();
175 for (iC = 0; iC <= colsTotal; iC++)
176 {
177 _with1.Cells[1, iC + 1].Value = DataGridView3.Columns[iC].HeaderText;
178 }
179 for (I = 0; I <= rowsTotal - 1; I++)
180 {
181 for (j = 0; j <= colsTotal; j++)
182 {
183 _with1.Cells[I + 2, j + 1].value = DataGridView3.Rows[I].Cells[j].Value;
184 }
185 }
186 _with1.Rows["1:1"].Font.FontStyle = "Bold";
187 _with1.Rows["1:1"].Font.Size = 12;
188
189 _with1.Cells.Columns.AutoFit();
190 _with1.Cells.Select();
191 _with1.Cells.EntireColumn.AutoFit();
192 _with1.Cells[1, 1].Select();
193 }
194 catch (Exception ex)
195 {
196 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
197 }
198 finally
199 {
200 //RELEASE ALLOACTED RESOURCES
201 System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
202 xlApp = null;
203 }
204 }
205
206 private void Button9_Click(object sender, EventArgs e)
207 {
208 DataGridView3.DataSource = null;
209 cmbCustomerName.Text = "";
210 GroupBox4.Visible = false;
211 }
212
213 private void Button2_Click(object sender, EventArgs e)
214 {
215 DataGridView1.DataSource = null;
216 dtpInvoiceDateFrom.Text = DateTime.Today.ToString();
217 dtpInvoiceDateTo.Text = DateTime.Today.ToString();
218 GroupBox3.Visible = false;
219 }
220
221 private void Button6_Click(object sender, EventArgs e)
222 {
223 DateTimePicker1.Text = DateTime.Today.ToString();
224 DateTimePicker2.Text = DateTime.Today.ToString();
225 DataGridView2.DataSource = null;
226 GroupBox10.Visible = false;
227 }
228 public void FillCombo()
229 {
230
231 try
232 {
233 con = new SqlConnection(cs.DBConn);
234 con.Open();
235 adp = new SqlDataAdapter();
236 adp.SelectCommand = new SqlCommand("SELECT distinct CustomerName FROM Invoice_Info,Customer where Invoice_Info.CustomerID=Customer.CustomerID",con);
237 ds = new DataSet("ds");
238 adp.Fill(ds);
239 dTable = ds.Tables[0];
240 cmbCustomerName.Items.Clear();
241 foreach (DataRow drow in dTable.Rows)
242 {
243 cmbCustomerName.Items.Add(drow[0].ToString());
244
245 }
246 }
247 catch (Exception ex)
248 {
249 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
250 }
251
252 }
253
254 private void Button1_Click(object sender, EventArgs e)
255 {
256 try
257 {
258 GroupBox3.Visible = true;
259 con = new SqlConnection(cs.DBConn);
260 con.Open();
261 cmd = new SqlCommand("SELECT RTRIM(invoiceNo) as [Order No],RTRIM(InvoiceDate) as [Order Date],RTRIM(Invoice_Info.CustomerID) as [Customer ID],RTRIM(CustomerName) as [Customer Name],RTRIM(SubTotal) as [SubTotal],RTRIM(VATPer) as [Vat+ST %],RTRIM(VATAmount) as [VAT+ST Amount],RTRIM(DiscountPer) as [Discount %],RTRIM(DiscountAmount) as [Discount Amount],RTRIM(GrandTotal) as [Grand Total],RTRIM(TotalPayment) as [Total Payment],RTRIM(PaymentDue) as [Payment Due],RTRIM(PaymentType) as [Payment Type],RTRIM(Status) as [Status],Remarks from Invoice_Info,Customer where Invoice_Info.CustomerID=Customer.CustomerID and InvoiceDate between @d1 and @d2 order by InvoiceDate desc", con);
262 cmd.Parameters.Add("@d1", SqlDbType.DateTime, 30, "InvoiceDate").Value = dtpInvoiceDateFrom.Value.Date;
263 cmd.Parameters.Add("@d2", SqlDbType.DateTime, 30, "InvoiceDate").Value = dtpInvoiceDateTo.Value.Date;
264 SqlDataAdapter myDA = new SqlDataAdapter(cmd);
265 DataSet myDataSet = new DataSet();
266 myDA.Fill(myDataSet, "Invoice_Info");
267 myDA.Fill(myDataSet, "Customer");
268 DataGridView1.DataSource = myDataSet.Tables["Customer"].DefaultView;
269 DataGridView1.DataSource = myDataSet.Tables["Invoice_Info"].DefaultView;
270 Int64 sum = 0;
271 Int64 sum1 = 0;
272 Int64 sum2 = 0;
273
274 foreach (DataGridViewRow r in this.DataGridView1.Rows)
275 {
276 Int64 i = Convert.ToInt64(r.Cells[9].Value);
277 Int64 j = Convert.ToInt64(r.Cells[10].Value);
278 Int64 k = Convert.ToInt64(r.Cells[11].Value);
279 sum = sum + i;
280 sum1 = sum1 + j;
281 sum2 = sum2 + k;
282
283 }
284 TextBox1.Text = sum.ToString();
285 TextBox2.Text = sum1.ToString();
286 TextBox3.Text = sum2.ToString();
287
288 con.Close();
289 }
290 catch (Exception ex)
291 {
292 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
293 }
294 }
295
296 private void cmbCustomerName_SelectedIndexChanged(object sender, EventArgs e)
297 {
298 try
299 {
300 GroupBox4.Visible = true;
301 cmbCustomerName.Text = cmbCustomerName.Text.Trim();
302 con = new SqlConnection(cs.DBConn);
303 con.Open();
304 cmd = new SqlCommand("SELECT RTRIM(invoiceNo) as [Order No],RTRIM(InvoiceDate) as [Order Date],RTRIM(Invoice_Info.CustomerID) as [Customer ID],RTRIM(CustomerName) as [Customer Name],RTRIM(SubTotal) as [SubTotal],RTRIM(VATPer) as [Vat+ST %],RTRIM(VATAmount) as [VAT+ST Amount],RTRIM(DiscountPer) as [Discount %],RTRIM(DiscountAmount) as [Discount Amount],RTRIM(GrandTotal) as [Grand Total],RTRIM(TotalPayment) as [Total Payment],RTRIM(PaymentDue) as [Payment Due],RTRIM(PaymentType) as [Payment Type],RTRIM(Status) as [Status],Remarks from Invoice_Info,Customer where Invoice_Info.CustomerID=Customer.CustomerID and Customername='" + cmbCustomerName.Text.Trim() + "' order by CustomerName,InvoiceDate", con);
305 SqlDataAdapter myDA = new SqlDataAdapter(cmd);
306 DataSet myDataSet = new DataSet();
307 myDA.Fill(myDataSet, "Invoice_Info");
308 myDA.Fill(myDataSet, "Customer");
309 DataGridView3.DataSource = myDataSet.Tables["Customer"].DefaultView;
310 DataGridView3.DataSource = myDataSet.Tables["Invoice_Info"].DefaultView;
311 Int64 sum = 0;
312 Int64 sum1 = 0;
313 Int64 sum2 = 0;
314
315 foreach (DataGridViewRow r in this.DataGridView3.Rows)
316 {
317 Int64 i = Convert.ToInt64(r.Cells[9].Value);
318 Int64 j = Convert.ToInt64(r.Cells[10].Value);
319 Int64 k = Convert.ToInt64(r.Cells[11].Value);
320 sum = sum + i;
321 sum1 = sum1 + j;
322 sum2 = sum2 + k;
323 }
324 TextBox6.Text = sum.ToString();
325 TextBox5.Text = sum1.ToString();
326 TextBox4.Text = sum2.ToString();
327
328 con.Close();
329 }
330 catch (Exception ex)
331 {
332 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
333 }
334 }
335
336 private void Button5_Click(object sender, EventArgs e)
337 {
338 try
339 {
340 GroupBox10.Visible = true;
341 con = new SqlConnection(cs.DBConn);
342 con.Open();
343 cmd = new SqlCommand("SELECT RTRIM(invoiceNo) as [Order No],RTRIM(InvoiceDate) as [Order Date],RTRIM(Invoice_Info.CustomerID) as [Customer ID],RTRIM(CustomerName) as [Customer Name],RTRIM(SubTotal) as [SubTotal],RTRIM(VATPer) as [Vat+ST %],RTRIM(VATAmount) as [VAT+ST Amount],RTRIM(DiscountPer) as [Discount %],RTRIM(DiscountAmount) as [Discount Amount],RTRIM(GrandTotal) as [Grand Total],RTRIM(TotalPayment) as [Total Payment],RTRIM(PaymentDue) as [Payment Due],RTRIM(PaymentType) as [Payment Type],RTRIM(Status) as [Status],Remarks from Invoice_Info,Customer where Invoice_Info.CustomerID=Customer.CustomerID and InvoiceDate between @d1 and @d2 and PaymentDue > 0 order by InvoiceDate desc", con);
344 cmd.Parameters.Add("@d1", SqlDbType.DateTime, 30, "InvoiceDate").Value = DateTimePicker2.Value.Date;
345 cmd.Parameters.Add("@d2", SqlDbType.DateTime, 30, "InvoiceDate").Value = DateTimePicker1.Value.Date;
346 SqlDataAdapter myDA = new SqlDataAdapter(cmd);
347 DataSet myDataSet = new DataSet();
348 myDA.Fill(myDataSet, "Invoice_Info");
349 myDA.Fill(myDataSet, "Customer");
350 DataGridView2.DataSource = myDataSet.Tables["Customer"].DefaultView;
351 DataGridView2.DataSource = myDataSet.Tables["Invoice_Info"].DefaultView;
352 Int64 sum = 0;
353 Int64 sum1 = 0;
354 Int64 sum2 = 0;
355
356 foreach (DataGridViewRow r in this.DataGridView2.Rows)
357 {
358 Int64 i = Convert.ToInt64(r.Cells[9].Value);
359 Int64 j = Convert.ToInt64(r.Cells[10].Value);
360 Int64 k = Convert.ToInt64(r.Cells[11].Value);
361 sum = sum + i;
362 sum1 = sum1 + j;
363 sum2 = sum2 + k;
364 }
365 TextBox12.Text = sum.ToString();
366 TextBox11.Text = sum1.ToString();
367 TextBox10.Text = sum2.ToString();
368
369 con.Close();
370 }
371 catch (Exception ex)
372 {
373 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
374 }
375 }
376
377 private void frmSalesRecord_FormClosing(object sender, FormClosingEventArgs e)
378 {
379 this.Hide();
380 frmSales frm = new frmSales();
381 frm.lblUser.Text = lblUser.Text;
382 frm.lblUserType.Text = lblUserType.Text;
383 frm.Show();
384 }
385
386 private void DataGridView1_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
387 {
388 try
389 {
390 DataGridViewRow dr = DataGridView1.SelectedRows[0];
391 this.Hide();
392 frmSales frmSales = new frmSales();
393 // or simply use column name instead of index
394 // dr.Cells["id"].Value.ToString();
395 frmSales.Show();
396 frmSales.txtInvoiceNo.Text = dr.Cells[0].Value.ToString();
397 frmSales.dtpInvoiceDate.Text = dr.Cells[1].Value.ToString();
398 frmSales.txtCustomerID.Text = dr.Cells[2].Value.ToString();
399 frmSales.txtCustomerName.Text = dr.Cells[3].Value.ToString();
400 frmSales.txtSubTotal.Text = dr.Cells[4].Value.ToString();
401 frmSales.txtTaxPer.Text = dr.Cells[5].Value.ToString();
402 frmSales.txtTaxAmt.Text = dr.Cells[6].Value.ToString();
403 frmSales.txtDiscountPer.Text = dr.Cells[7].Value.ToString();
404 frmSales.txtDiscountAmount.Text = dr.Cells[8].Value.ToString();
405 frmSales.txtTotal.Text = dr.Cells[9].Value.ToString();
406 frmSales.txtTotalPayment.Text = dr.Cells[10].Value.ToString();
407 frmSales.txtPaymentDue.Text = dr.Cells[11].Value.ToString();
408 frmSales.cmbPaymentType .Text = dr.Cells[12].Value.ToString();
409 frmSales.cmbStatus.Text = dr.Cells[13].Value.ToString();
410 frmSales.txtRemarks.Text = dr.Cells[14].Value.ToString();
411 frmSales.btnUpdate.Enabled = true;
412 frmSales.Delete.Enabled = true;
413 frmSales.btnPrint.Enabled = true;
414 frmSales.Save.Enabled = false;
415 frmSales.lblUser.Text = lblUser.Text;
416 frmSales.lblUserType.Text = lblUserType.Text;
417 con = new SqlConnection(cs.DBConn);
418 con.Open();
419 cmd = new SqlCommand("SELECT Product.ProductID,ProductSold.Productname,ProductSold.Price,ProductSold.Quantity,ProductSold.TotalAmount from Invoice_Info,ProductSold,Product where Invoice_info.InvoiceNo=ProductSold.InvoiceNo and Product.ProductID=ProductSold.ProductID and invoice_Info.InvoiceNo='" + dr.Cells[0].Value.ToString() + "'", con);
420 rdr = cmd.ExecuteReader();
421 while (rdr.Read()==true)
422 {
423 ListViewItem lst = new ListViewItem();
424 lst.SubItems.Add(rdr[0].ToString().Trim());
425 lst.SubItems.Add(rdr[1].ToString().Trim());
426 lst.SubItems.Add(rdr[2].ToString().Trim());
427 lst.SubItems.Add(rdr[3].ToString().Trim());
428 lst.SubItems.Add(rdr[4].ToString().Trim());
429 frmSales.ListView1.Items.Add(lst);
430 }
431 frmSales.ListView1.Enabled = false;
432 frmSales.Button7.Enabled = false;
433 }
434 catch (Exception ex)
435 {
436 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
437 }
438 }
439
440 private void DataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
441 {
442 string strRowNumber = (e.RowIndex + 1).ToString();
443 SizeF size = e.Graphics.MeasureString(strRowNumber, this.Font);
444 if (DataGridView1.RowHeadersWidth < Convert.ToInt32((size.Width + 20)))
445 {
446 DataGridView1.RowHeadersWidth = Convert.ToInt32((size.Width + 20));
447 }
448 Brush b = SystemBrushes.ControlText;
449 e.Graphics.DrawString(strRowNumber, this.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2));
450
451 }
452
453 private void DataGridView3_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
454 {
455 try
456 {
457 DataGridViewRow dr = DataGridView3.SelectedRows[0];
458 this.Hide();
459 frmSales frmSales = new frmSales();
460 // or simply use column name instead of index
461 // dr.Cells["id"].Value.ToString();
462 frmSales.Show();
463 frmSales.txtInvoiceNo.Text = dr.Cells[0].Value.ToString();
464 frmSales.dtpInvoiceDate.Text = dr.Cells[1].Value.ToString();
465 frmSales.txtCustomerID.Text = dr.Cells[2].Value.ToString();
466 frmSales.txtCustomerName.Text = dr.Cells[3].Value.ToString();
467 frmSales.txtSubTotal.Text = dr.Cells[4].Value.ToString();
468 frmSales.txtTaxPer.Text = dr.Cells[5].Value.ToString();
469 frmSales.txtTaxAmt.Text = dr.Cells[6].Value.ToString();
470 frmSales.txtDiscountPer.Text = dr.Cells[7].Value.ToString();
471 frmSales.txtDiscountAmount.Text = dr.Cells[8].Value.ToString();
472 frmSales.txtTotal.Text = dr.Cells[9].Value.ToString();
473 frmSales.txtTotalPayment.Text = dr.Cells[10].Value.ToString();
474 frmSales.txtPaymentDue.Text = dr.Cells[11].Value.ToString();
475 frmSales.cmbPaymentType.Text = dr.Cells[12].Value.ToString();
476 frmSales.cmbStatus.Text = dr.Cells[13].Value.ToString();
477 frmSales.txtRemarks.Text = dr.Cells[14].Value.ToString();
478 frmSales.btnUpdate.Enabled = true;
479 frmSales.Delete.Enabled = true;
480 frmSales.btnPrint.Enabled = true;
481 frmSales.Save.Enabled = false;
482 frmSales.lblUser.Text = lblUser.Text;
483 frmSales.lblUserType.Text = lblUserType.Text;
484 con = new SqlConnection(cs.DBConn);
485 con.Open();
486 cmd = new SqlCommand("SELECT Product.ProductID,ProductSold.Productname,ProductSold.Price,ProductSold.Quantity,ProductSold.TotalAmount from Invoice_Info,ProductSold,Product where Invoice_info.InvoiceNo=ProductSold.InvoiceNo and Product.ProductID=ProductSold.ProductID and invoice_Info.InvoiceNo='" + dr.Cells[0].Value.ToString() + "'", con);
487 rdr = cmd.ExecuteReader();
488 while (rdr.Read() == true)
489 {
490 ListViewItem lst = new ListViewItem();
491 lst.SubItems.Add(rdr[0].ToString().Trim());
492 lst.SubItems.Add(rdr[1].ToString().Trim());
493 lst.SubItems.Add(rdr[2].ToString().Trim());
494 lst.SubItems.Add(rdr[3].ToString().Trim());
495 lst.SubItems.Add(rdr[4].ToString().Trim());
496 frmSales.ListView1.Items.Add(lst);
497 }
498 frmSales.ListView1.Enabled = false;
499 frmSales.Button7.Enabled = false;
500 }
501 catch (Exception ex)
502 {
503 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
504 }
505 }
506
507 private void DataGridView3_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
508 {
509 string strRowNumber = (e.RowIndex + 1).ToString();
510 SizeF size = e.Graphics.MeasureString(strRowNumber, this.Font);
511 if (DataGridView3.RowHeadersWidth < Convert.ToInt32((size.Width + 20)))
512 {
513 DataGridView3.RowHeadersWidth = Convert.ToInt32((size.Width + 20));
514 }
515 Brush b = SystemBrushes.ControlText;
516 e.Graphics.DrawString(strRowNumber, this.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2));
517
518 }
519
520 private void DataGridView2_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
521 {
522 string strRowNumber = (e.RowIndex + 1).ToString();
523 SizeF size = e.Graphics.MeasureString(strRowNumber, this.Font);
524 if (DataGridView2.RowHeadersWidth < Convert.ToInt32((size.Width + 20)))
525 {
526 DataGridView2.RowHeadersWidth = Convert.ToInt32((size.Width + 20));
527 }
528 Brush b = SystemBrushes.ControlText;
529 e.Graphics.DrawString(strRowNumber, this.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2));
530
531 }
532
533 private void DataGridView2_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
534 {
535 try
536 {
537 DataGridViewRow dr = DataGridView2.SelectedRows[0];
538 this.Hide();
539 frmSales frmSales = new frmSales();
540 // or simply use column name instead of index
541 // dr.Cells["id"].Value.ToString();
542 frmSales.Show();
543 frmSales.txtInvoiceNo.Text = dr.Cells[0].Value.ToString();
544 frmSales.dtpInvoiceDate.Text = dr.Cells[1].Value.ToString();
545 frmSales.txtCustomerID.Text = dr.Cells[2].Value.ToString();
546 frmSales.txtCustomerName.Text = dr.Cells[3].Value.ToString();
547 frmSales.txtSubTotal.Text = dr.Cells[4].Value.ToString();
548 frmSales.txtTaxPer.Text = dr.Cells[5].Value.ToString();
549 frmSales.txtTaxAmt.Text = dr.Cells[6].Value.ToString();
550 frmSales.txtDiscountPer.Text = dr.Cells[7].Value.ToString();
551 frmSales.txtDiscountAmount.Text = dr.Cells[8].Value.ToString();
552 frmSales.txtTotal.Text = dr.Cells[9].Value.ToString();
553 frmSales.txtTotalPayment.Text = dr.Cells[10].Value.ToString();
554 frmSales.txtPaymentDue.Text = dr.Cells[11].Value.ToString();
555 frmSales.cmbPaymentType.Text = dr.Cells[12].Value.ToString();
556 frmSales.cmbStatus.Text = dr.Cells[13].Value.ToString();
557 frmSales.txtRemarks.Text = dr.Cells[14].Value.ToString();
558 frmSales.btnUpdate.Enabled = true;
559 frmSales.Delete.Enabled = true;
560 frmSales.btnPrint.Enabled = true;
561 frmSales.Save.Enabled = false;
562 frmSales.lblUser.Text = lblUser.Text;
563 frmSales.lblUserType.Text = lblUserType.Text;
564 con = new SqlConnection(cs.DBConn);
565 con.Open();
566 cmd = new SqlCommand("SELECT Product.ProductID,ProductSold.Productname,ProductSold.Price,ProductSold.Quantity,ProductSold.TotalAmount from Invoice_Info,ProductSold,Product where Invoice_info.InvoiceNo=ProductSold.InvoiceNo and Product.ProductID=ProductSold.ProductID and invoice_Info.InvoiceNo='" + dr.Cells[0].Value.ToString() + "'", con);
567 rdr = cmd.ExecuteReader();
568 while (rdr.Read() == true)
569 {
570 ListViewItem lst = new ListViewItem();
571 lst.SubItems.Add(rdr[0].ToString().Trim());
572 lst.SubItems.Add(rdr[1].ToString().Trim());
573 lst.SubItems.Add(rdr[2].ToString().Trim());
574 lst.SubItems.Add(rdr[3].ToString().Trim());
575 lst.SubItems.Add(rdr[4].ToString().Trim());
576 frmSales.ListView1.Items.Add(lst);
577 }
578 frmSales.ListView1.Enabled = false;
579 frmSales.Button7.Enabled = false;
580 }
581 catch (Exception ex)
582 {
583 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
584 }
585 }
586
587 private void TabControl1_Click(object sender, EventArgs e)
588 {
589 DataGridView1.DataSource = null;
590 dtpInvoiceDateFrom.Text = DateTime.Today.ToString();
591 dtpInvoiceDateTo.Text = DateTime.Today.ToString();
592 GroupBox3.Visible = false;
593 DataGridView3.DataSource = null;
594 cmbCustomerName.Text = "";
595 GroupBox4.Visible = false;
596 DateTimePicker1.Text = DateTime.Today.ToString();
597 DateTimePicker2.Text = DateTime.Today.ToString();
598 DataGridView2.DataSource = null;
599 GroupBox10.Visible = false;
600
601 }
602
603 private void cmbCustomerName_Format(object sender, ListControlConvertEventArgs e)
604 {
605 if (object.ReferenceEquals(e.DesiredType, typeof(string)))
606 {
607 e.Value = e.Value.ToString().Trim();
608 }
609 }
610 }
611
612 }